package com.example.ccj.b.c.dialog;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.ccj.R;
import com.example.ccj.b.c.draw.SelfCircleProgressView;


public class DownLoadDialog extends DialogBase{
    private LinearLayout mLlUploadFile;
    private LinearLayout mLlLoadingView;
    private ImageView mIvLoading;
    private TextView progressText;
    private SelfCircleProgressView uploadProgress;
    int max;


    public DownLoadDialog(@NonNull Context context, int max) {
        super(context);
        this.max = max;
    }

    @Override
    public void onInit() {
        setLayout(R.layout.dialog_load_net_work_data);
        isCanClose(false);
        noInstallWidth();//不沾满宽度
        setAlpha(0.8f);//透明度
        setCancelable(false);//点击不允许关闭
        isShowBackground(false);//不显示背景


        mLlUploadFile = findViewById(R.id.dialog_progress_upload_layout_1);
        mLlLoadingView = findViewById(R.id.loading_layout_3);
        mIvLoading = findViewById(R.id.loading_img);
        mIvLoading.setImageResource(R.mipmap.loading_dialog);
        uploadProgress = findViewById(R.id.upload_layout);
        progressText = findViewById(R.id.dialog_progress_upload_text);
        mLlLoadingView.setVisibility(View.GONE);
        mLlUploadFile.setVisibility(View.VISIBLE);
        uploadProgress.setMax(max);

    }

    public void setMaxSpeed(int maxSpeed){
        this.max = maxSpeed;
        uploadProgress.post(new Runnable() {
            @Override
            public void run() {
                uploadProgress.setMax(max);
            }
        });
    }

    /**
     * 填写进度
     * @param speed 进度
     */
    public void setSpeed(int speed){
        if (speed >= max) dismiss();
        uploadProgress.post(new Runnable() {
            @Override
            public void run() {
                uploadProgress.setCurrent(speed);
            }
        });
    }

    /**
     * 填写进度文本
     * @param text 进度提示
     */
    public void setUploadText(String text){
        progressText.post(new Runnable() {
            @Override
            public void run() {
                progressText.setText(text);
            }
        });
    }
}
